﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VK.Casemeet.Links;
using VK.Comm;

namespace VK.Casemeet.Web.Admin.Links
{
    public partial class LinkAdd : System.Web.UI.Page
    {
        public string imgUrl = "Null.jpg";

        protected void Page_Load(object sender, EventArgs e)
        {
            (this.Master as Site).SiteMapPathControl.MapPathList = new List<MapPath>(){
                new MapPath{ Text="桌面",Url="/Admin/Home.aspx"},
                new MapPath{ Text="友情链接",Url="Index.aspx"},
                new MapPath{ Text="新建友链",Url="#"}
            };

            if (!IsPostBack)
            {
                LinkHelper.BindTypeRad(radType);
            }
        }

        protected void butSave_Click(object sender, EventArgs e)
        {
            LinkEntity brand = LoadEntity();

            if (LinkBLL.InsertLink(brand) > 0)
            {
                Message.Msg(this.Page, CS.MsgAddSuccess, MessageType.Success);
                Util.ClearControl((this.Master as Site).contentBody.Controls);
                txtHits.Text = "0";
            }
            else
            {
                Message.Msg(this.Page, CS.MsgAddFailure, MessageType.Failure);
            }
        }

        protected LinkEntity LoadEntity()
        {
            LinkEntity link = new LinkEntity();
            link.Name = txtName.Text;
            link.Type = int.Parse(radType.SelectedValue);
            link.Url = txtUrl.Text;
            link.Detail = txtDetail.Text;
            link.Hits = int.Parse(txtHits.Text);
            link.Sort = int.Parse(txtSort.Text);
            link.ImageUrl = Util.GetFormString("hidImgUrl");

            return link;
        }
    }
}